package com.newstart.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * Created by liushijie on 2018/5/28.
 */
@Service
public class RedisService {
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;


    public void setHash(String key, String hashKey, Object object, long s) {
        redisTemplate.opsForHash().put(key, hashKey, object);
        if (s > 0) redisTemplate.expire(key, s, TimeUnit.SECONDS);
    }

    public Object getHash(String key, String hashKey) {
        return redisTemplate.opsForHash().get(key, hashKey);
    }


}
